package com.sgb.kjwl.view.ui.adapter.business;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.ApplyEntity;
import com.sgb.kjwl.model.entity.businessmanagement.CompanyEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class CompanyListAdapter extends BaseRecycleAdapter<CompanyEntity> {

    private TextView tvName;
    private TextView tvLine;
    private ImageView ivLogo;

    public CompanyListAdapter(Context context, List<CompanyEntity> datas) {
        super(context, R.layout.item_company_list, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final CompanyEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        tvName = holder.getItem().findViewById(R.id.tv_name);
        tvLine = holder.getItem().findViewById(R.id.tv_line);
        ivLogo = holder.getItem().findViewById(R.id.iv_logo);

        RequestOptions options = new RequestOptions().placeholder(context.getResources().getDrawable(R.drawable.icon_no_logo));
        Glide.with(context).load(entity.getCompLogo()).apply(options).into(ivLogo);

        tvName.setText(entity.getCompName());

        if (holder.getPosition() == datas.size()){
            tvLine.setVisibility(View.GONE);
        }else {
            tvLine.setVisibility(View.VISIBLE);
        }
    }

    private CompanyListAdapter.onEditClickListener editClickListener;

    public void setonEditClick(CompanyListAdapter.onEditClickListener editClickListener) {
        this.editClickListener = editClickListener;
    }

    public interface onEditClickListener {
        void onDetailedListClick(ApplyEntity entity, int position);

        void onInviteOfferClick(ApplyEntity entity, int position);
    }
}
